import request from '@/router/axios';
// --------------- API配置 ----------------------
/**
 * 新增或编辑API
 */
export const addOrUpdateApi = (row) => {
  return request({
    url: '/api/mes-product/apaas/api/submit',
    method: 'post',
    data: row
  });
};

/**
 * 根据APIid查询API信息
 */
export const getApiInfo = (id) => {
  return request({
    url: '/api/mes-product/apaas/api/detail',
    method: 'get',
    params: {
      id
    }
  });
};

// --------------- 工站作业 ---------------------

/**
 * 根据工单号查询工单详情
 */
export const getDetailByWorkOrderNo = (workOrderNo) => {
  return request({
    url: '/api/mes-product/work-order/detail',
    method: 'get',
    params: {
      workOrderNo
    }
  });
};

/**
 * 根据工单查询工艺
 */
export const getProcessRoute = (params) => {
  return request({
    url: '/api/mes-product/process/product-route/workorder-routes',
    method: 'get',
    params: params
  });
};
/**
 * 根据工单编号查询工艺
 */
export const getProcessRouteByNo = (params) => {
  return request({
    url: '/api/mes-product/process/product-route/workorder-routes-by-no',
    method: 'get',
    params: params
  });
};
/**
 * 技能管控
 */
export const checkSkill = (data) => {
  return request({
    url: '/api/mes-product/workorder-station/check-route-skill-station',
    method: 'post',
    data: data
  });
};
/**
 * 检查工位
 */
export const checkStation = (code) => {
  return request({
    url: '/api/mes-product/station/check',
    method: 'post',
    params: {
      code
    }
  });
};

/**
 * 绑定工位
 */
export const bindingStation = (data) => {
  return request({
    url: '/api/mes-product/workorder-station/binding-station',
    method: 'post',
    data: data
  });
};

/**
 * 检查员工编码
 */
export const checkUserCode = (code) => {
  return request({
    url: '/api/blade-system/user/check',
    method: 'get',
    params: {
      code
    }
  });
};

/**
 * 协同作业登记或退出
 */
export const collaborativeOperation = (data) => {
  return request({
    url: '/api/mes-product/workorder-station/cooperator/submit',
    method: 'post',
    data: data
  });
};

/**
 * 获取协同作业人员
 */
export const getcooperatorList = (workorderStationId) => {
  return request({
    url: '/api/mes-product/workorder-station/cooperator/list',
    method: 'get',
    params: {
      workorderStationId
    }
  });
};

// --------------- 工站配置 ---------------------

/**
 * 获取分页查询工站列表
 */
export const getStationtList = (current, size, params) => {
  return request({
    url: '/api/mes-product/apaasworkstation/page',
    method: 'post',
    params: {
      ...params,
      current,
      size
    }
  });
};

/**
 * 新增或编辑工站UI
 */
export const SaveStationuiDesignApi = (row) => {
  return request({
    url: '/api/mes-product/apaasworkstation/submit',
    method: 'post',
    data: row
  });
};

/**
 * 获取工站详情
 */
export const getWorkStationDetail = (id) => {
  return request({
    url: '/api/mes-product/apaasworkstation/detail',
    method: 'get',
    params: {
      id
    }
  });
};

/**
 * 根据工单工序获取工序详情
 */
export const getRouteDetail = (workOrderId, routeCode) =>
  request({
    url: '/api/mes-product/process/route/detail',
    method: 'get',
    params: {
      workOrderId,
      routeCode
    }
  });

/**
 * 逻辑删除工站列表信息
 */
export const removeStationtInfo = (ids) => {
  return request({
    url: '/api/mes-product/apaasworkstation/remove',
    method: 'get',
    params: {
      ids
    }
  });
};

/**
 * 检查工序是否锁定
 */
export const checkRoute = (workOrderId, routeCode) =>
  request({
    url: '/api/mes-product/process/route/check',
    method: 'get',
    params: {
      workOrderId,
      routeCode
    }
  });

/**
 * 获取分页查询工站模版列表
 */
export const getStationtTemplateList = (current, size, params) => {
  return request({
    url: '/api/mes-product/apaas/workstation/template/page',
    method: 'get',
    params: {
      ...params,
      current,
      size
    }
  });
};

/**
 * 新增或编辑工站模版UI
 */
export const SaveStationuiTemplateDesign = (row) => {
  return request({
    url: '/api/mes-product/apaas/workstation/template/submit',
    method: 'post',
    data: row
  });
};

/**
 * 获取工站模版详情
 */
export const getWorkStationTemplateDetail = (id) => {
  return request({
    url: '/api/mes-product/apaas/workstation/template/detail',
    method: 'get',
    params: {
      id
    }
  });
};

/**
 * 逻辑删除工站模版列表信息
 */
export const removeStationtTemplateInfo = (ids) => {
  return request({
    url: '/api/mes-product/apaas/workstation/template/remove',
    method: 'post',
    params: {
      ids
    }
  });
};

/**
 * 获取工站模版下拉数据
 */
export const getWorkStationTemplateSelect = (clientType) => {
  return request({
    url: '/api/mes-product/apaas/workstation/template/select',
    method: 'get',
    params: {
      clientType
    }
  });
};

/**
 * 获取系统字典配置
 */
export const getVehicleTypeSelect = (code) => {
  return request({
    url: '/api/blade-system/dict/dictionary',
    method: 'get',
    params: {
      code
    }
  });
};

/**
 * 查询已登记工装治具列表
 */
export const getOperationTool = (workorderStationId, status, toolType) => {
  return request({
    url: '/api/mes-product/operation-tool/list',
    method: 'get',
    params: {
      workorderStationId,
      status,
      toolType
    }
  });
};

/**
 * 工装治具登记
 */
export const bindingTool = (row) => {
  return request({
    url: '/api/mes-product/operation-tool/binding',
    method: 'post',
    data: row
  });
};

/**
 * 解绑工装治具
 */
export const unbindingTool = (row) => {
  return request({
    url: '/api/mes-product/operation-tool/unbinding',
    method: 'post',
    data: row
  });
};

/**
 * 根据设备编码查询设备信息
 */
export const getEquipmentInfoByCode = (code) => {
  return request({
    url: '/api/mes-product/ems-equipment/info',
    method: 'get',
    params: {
      code
    }
  });
};

/**
 * 绑定设备
 */
export const bindingEquipment = (row) => {
  return request({
    url: '/api/mes-product/operation-tool/equipment/binding',
    method: 'post',
    data: row
  });
};

/**
 * 绑定辅料
 */
export const bindingAccessories = (row) => {
  return request({
    url: '/api/mes-product/operation-tool/accessories/binding',
    method: 'post',
    data: row
  });
};

/**
 * 解绑辅料
 */
export const unbindingAccessories = (row) => {
  return request({
    url: '/api/mes-product/operation-tool/accessories/unbinding',
    method: 'post',
    data: row
  });
};

/**
 * 查询所有绑定的辅料
 */
export const getAccessoriesList = (workOrderStationId) => {
  return request({
    url: '/api/mes-product/part/indirect/usage/not/expired/list',
    method: 'get',
    params: {
      workOrderStationId
    }
  });
};

/**
 * 根据不良代码查询不良信息
 */
export const getFailureInfoByCode = (params) => {
  return request({
    url: '/api/mes-product/mro-dict/check-code',
    method: 'get',
    params: params
  });
};

/**
 * 登记不良信息
 */
export const saveFailureInfo = (data) => {
  return request({
    url: '/api/mes-product/mro-repair-register/register',
    method: 'post',
    data: data
  });
};

export const failureEnter = (data) => {
  return request({
    url: '/api/mes-product/mro/centerproduct/input',
    method: 'post',
    data
  });
};

export const getAllSection = () => {
  return request({
    url: '/api/mes-product/work-section/all-section',
    method: 'get'
  });
};

export const saveWorkSection = (data) => {
  return request({
    url: '/api/mes-product/apaasworkstation/bindWorkSection',
    method: 'post',
    data: data
  });
};

export const getSnProductInfo = (sequenceNumber) => {
  return request({
    url: '/api/mes-product/product/check-sequence-number',
    method: 'get',
    params: {
      sequenceNumber
    }
  });
};

export const getPlmSessionId = (params) => {
  return request({
    url: '/api/mes-docking/template-data/get/sessionid',
    method: 'get',
    params
  });
};

export const getPlmEsopId = (data) => {
  return request({
    url: '/api/mes-docking/template-data/list-by-partno',
    method: 'post',
    data: data
  });
};

export const getPlmEsopUrl = (data) => {
  return request({
    url: '/api/mes-docking/template-data/down-url-by-docid',
    method: 'post',
    data
  });
};

export const checkPackNo = (data) => {
  return request({
    url: '/api/mes-product/workorder/check/packNo',
    method: 'post',
    data
  });
};

export const workOrderfeeding = (data) => {
  return request({
    url: '/api/mes-product/workorder/station/feeding',
    method: 'post',
    data
  });
};

export const getFeedingList = (params) => {
  return request({
    url: '/api/mes-product/workorder/material/feeding/list',
    method: 'get',
    params: params
  });
};

export const getNoKeyFeedingData = (params) => {
  return request({
    url: '/api/mes-product/workorder/feeding/sectionCode/list',
    method: 'get',
    params: params
  });
};

export const getLineDetail = (id) => {
  return request({
    url: '/api/mes-product/productionline/detail',
    method: 'get',
    params: {
      id
    }
  });
};

export const checkIsFeeding = (workOrderNo) => {
  return request({
    url: '/api/mes-product/workorder-station/check-work-order-station',
    method: 'get',
    params: {
      workOrderNo
    }
  });
};

export const toolRelation = (params) => {
  return request({
    url: '/api/mes-product/ems-equipment/equipment-tool/relation',
    method: 'get',
    params: params
  });
};

export const getToolTypeList = () => {
  return request({
    url: '/api/blade-system/dict/dictionary?code=tool_type_select',
    method: 'get'
  });
};

export const getMachineUseRecord = (params) => {
  return request({
    url: '/api/mes-product/ems-equipment/get/pre-machine/usage/record',
    method: 'get',
    params: params
  });
};

export const submitToolList = (data) => {
  return request({
    url: '/api/mes-product/ems-equipment-usage/transaction',
    method: 'post',
    data: data
  });
};

export const getAlreadyOnMachine = (params) => {
  return request({
    url: '/api/mes-product/ems-equipment-usage/work-order/already-on-machine',
    method: 'get',
    params: params
  });
};

export const checkWorkstation = (id) => {
  return request({
    url: '/api/mes-product/apaasworkstation/able/check',
    method: 'get',
    params: {
      id
    }
  });
};

export const workstationEnable = (id) => {
  return request({
    url: '/api/mes-product/apaasworkstation/able',
    method: 'get',
    params: {
      id,
      status: 1
    }
  });
};

export const workstationDisable = (id) => {
  return request({
    url: '/api/mes-product/apaasworkstation/able',
    method: 'get',
    params: {
      id,
      status: 0
    }
  });
};

export const getViewSettingList = (code) => {
  return request({
    url: `/api/mes-admin/page-element-config/list-by-code?code=${code}`,
    method: 'post'
  });
};

export const getOpenLineCheckResult = (params) => {
  return request({
    url: '/api/mes-product/line/inspection/get-result',
    method: 'get',
    params: params
  });
};

export const submitOpenLineCheckResult = (data) => {
  return request({
    url: '/api/mes-product/line/inspection/submit',
    method: 'post',
    data: data
  });
};
